<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:40:"template/img/default/img_site\index.html";i:1527058571;}*/ ?>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $seo['title']; ?></title>
    <meta name="keywords" content="<?php echo $seo['keyword']; ?>">
    <meta name="description" content="<?php echo $seo['desc']; ?>">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/h5/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/h5/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="/static/h5/css/animate.css" rel="stylesheet">
    <link href="/static/h5/css/style.css?v=4.1.0" rel="stylesheet">
    <style type="text/css">

        .operating{float:right; padding-top: 10px;}
        .operating span{margin: 0 3px; cursor: pointer}
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12 animated fadeInRight">
                <div class="mail-box-header">
                    <h2>网站列表</h2>
                    <div class="mail-tools tooltip-demo m-t-md">
                        <button class="btn btn-white btn-sm"  title="新增网站" data-toggle="modal" data-target="#modelWeb"><i class="fa fa-plus"></i> 新增网站</button>
                    </div>
                </div>
                <div class="mail-box">
                    <div class="forum-container" style="border-top: 1px solid #e7eaec">
                        <?php if(is_array($res) || $res instanceof \think\Collection || $res instanceof \think\Paginator): $i = 0; $__LIST__ = $res;if( count($__LIST__)==0 ) : echo "没有数据了" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                        <div class="forum-item active">
                            <div class="row">
                                <div class="col-sm-9" onclick="clickEdit('<?php echo $vo['id']; ?>')" data-toggle="modal" data-target="#modelWeb">
                                    <div class="forum-icon"><span style="font-size: 30px"><?php echo $vo['id']; ?></span></div>
                                    <a href="javascript:void(0)"   class="forum-item-title"><?php echo $vo['name']; ?></a>
                                    <div class="forum-sub-title"><?php echo $vo['domain']; ?></div>
                                </div>
                                <div class="col-sm-1 forum-info">
                                        <span class="views-number">
                                            <?php echo $vo['img_count']; ?>
                                        </span>
                                    <div>
                                        <small>图片</small>
                                    </div>
                                </div>
                                <div class="col-sm-2 forum-info">
                                    <div class="operating">
                                        <span class="label label-primary pull-left" onclick="clearData('<?php echo $vo['id']; ?>')">清除数据</span>
                                        <span class="label label-warning pull-left" onclick="clickEdit('<?php echo $vo['id']; ?>')" data-toggle="modal" data-target="#modelWeb">修改</span>
                                        <span class="label label-danger pull-left" onclick="deleteSite('<?php echo $vo['id']; ?>')">删除</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php endforeach; endif; else: echo "没有数据了" ;endif; ?>
                    </div>

                </div>



            </div>
        </div>
    </div>

    
    <div class="modal inmodal in" id="modelWeb" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated fadeIn">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true" onclick="closeBtn()">×</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="modelTitle">新增网站</h4>
                </div>
                <div class="modal-body">
                    <form role="form" name="form1" id="">
                        <input type="hidden" name="id" value="">
                        <div class="form-group">
                            <label>网站名称</label>
                            <input type="text" name="name" placeholder="请输入网站名称" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>域名</label>
                            <input type="text" name="domain" placeholder="请输入域名" class="form-control" value="http://">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal" onclick="closeBtn()">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="btn()">保存</button>
                </div>
            </div>
        </div>
   </div>

    <!-- 全局js -->
    <script src="/static/h5/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/h5/js/bootstrap.min.js?v=3.3.6"></script>


    <!-- layer javascript -->
    <script src="/static/h5/js/plugins/layer/layer.min.js"></script>

    <script>
        // 决定Model显示数据 1：新增，2：修改
        var formType = 1;
        $(document).ready(function () {

            // 点击模态窗空白区域，触发事件
            $('#modelWeb').on('hide.bs.modal', function () {
                closeBtn()
            })

        });

        // click btn
        function btn(){
            var id = form1.id.value
            var name =form1.name.value;
            var domain = form1.domain.value;

            if(formType==1){
                // 新增
                add(name,domain);
            }else{
                //修改
                doEdit(id,name,domain);
            }
            // 刷新页面
            //console.log(1)

        }

        // 确认添加网站
        function add(name,domain){
            if(name==""){
                parent.layer.msg('网站名称不能为空');
                return false;
            }
            if(domain==""){
                parent.layer.msg('域名不能为空');
                return false;
            }
            $.ajax({
                url:"<?php echo url('imgSite/ajaxDoAdd'); ?>",
                data:{'name':name,'domain':domain},
                success:function(res){
                    //console.log(res);
                    if(res.code==200){
                        window.location.href="<?php echo url('imgSite/index'); ?>";
                    }
                },error:function(){

                }
            });
        }
        // 点击修改
        function clickEdit(id){

            // id为空，弹出错误
            if(id.length<1){
                parent.layer.msg('参数有误');
                return false;
            }
            // 重新赋予类型
            formType =2;

            // ajax请求当前id数据
            $.ajax({
                url:"<?php echo url('imgSite/ajaxInfo'); ?>",
                data:{'id':id},
                success:function(res){
                    //console.log(res)
                    if(res.code==200){
                        //$("form1").value()
                        form1.id.value = res.data.id;
                        form1.name.value = res.data.name;
                        form1.domain.value = res.data.domain;
                        $("#modelTitle").text('修改网站');
                    }else{
                        parent.layer.msg('数据请求失败');
                    }
                },error:function(){
                    parent.layer.msg('网络出现故障');
                }
            })


        }
        // 确认修改
        function doEdit(id,name,domain){
            $.ajax({
                url:"<?php echo url('imgSite/ajaxDoEdit'); ?>",
                data:{'id':id,'name':name,'domain':domain},
                success:function(res){
                    //console.log(res);
                    parent.layer.msg(res.msg);
                    window.location.href="<?php echo url('imgSite/index'); ?>";
                },error:function(){
                    parent.layer.msg('网络出现故障');
                }
            });
        }

        // 点击关闭按钮
        function closeBtn(){
            // 销毁参数
            $("#modelTitle").text('新增网站');
            form1.name.id = '';
            form1.name.value ='';
            form1.domain.value='http://';
            formType =1;
        }

        // 清除数据
        function clearData(a){
            $.ajax({
                url:"<?php echo url('img_site/clearSite'); ?>",
                data:{"id":a},
                success:function(res){
                    if(res.code==200){
                        parent.layer.msg(res.msg);
                    }else{
                        parent.layer.msg(res.msg);
                    }
                },error:function(){
                    parent.layer.msg('网络出现故障');
                }
            })

        }
        // 删除站点
        function deleteSite(a){
            $.ajax({
                url:"<?php echo url('img_site/deleteSite'); ?>",
                data:{"id":a},
                success:function(res){
                    if(res.code==200){
                        parent.layer.msg(res.msg);
                        window.location.href="<?php echo url('imgSite/index'); ?>";
                    }else{
                        parent.layer.msg(res.msg);
                    }
                    //console.log(res);
                },error:function(){
                    parent.layer.msg('网络出现故障');
                }
            })
        }

    </script>


</body>

</html>
